#include "NetworkForwardProxy.hpp"

NetworkForwardProxy::NetworkForwardProxy()
{
}

void NetworkForwardProxy::Boot()
{
  connection=sdbus::createSessionBusConnection(InterfaceName);
  proxy=sdbus::createObject(*connection,"/org/HBTY/NetworkForward");
  proxy->registerMethod("GetNetworkPort").onInterface(InterfaceName).implementedAs(funcGetNetworkPort);
  proxy->registerMethod("CreateTask").onInterface(InterfaceName).implementedAs(funcCreateTask);
  proxy->registerMethod("GetStudentInfo").onInterface(InterfaceName).implementedAs(funcGetStudentInfo);
  proxy->registerMethod("MobileConnectChange").onInterface(InterfaceName).implementedAs(funcMobileConnectChange);
  proxy->registerMethod("StartRecord").onInterface(InterfaceName).implementedAs(funcStartRecord);
  proxy->registerMethod("StopRecord").onInterface(InterfaceName).implementedAs(funcStopRecord);
  proxy->registerMethod("GetRecordStatus").onInterface(InterfaceName).implementedAs(funcGetRecordStatus);
  proxy->finishRegistration();
  
  workThread=std::thread([this](){
    connection->enterEventLoop();
  });
}

NetworkForwardProxy::~NetworkForwardProxy()
{
  if(workThread.joinable())
  {
    connection->leaveEventLoop();
    workThread.join();
  }
}

